package com.an.arrays;

public class SortTset {
    public static void main(String[] args) {
        int[] arr={2,412,654,32,86,343,85,21};
        A a = new A();
        //a.bubble(arr);
        //a.print(arr);
        a.bubble_2(arr, new Compare(){
            public int compare(int x1,int x2){
                return x2-x1;
            }
        });
        a.print(arr);


    }
}

class A{
    //冒泡排序
    public void bubble(int [] arr){
        for(int i=0;i<arr.length-1;i++){
            for(int j=0;j<arr.length-1-i;j++){
                if(arr[j]>arr[j+1]){
                    int tem=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=tem;
                }
            }
        }
    }

    //接口+冒泡
    public void bubble_2(int [] arr,Compare c){
        for(int i=0;i<arr.length-1;i++){
            for(int j=0;j<arr.length-1-i;j++){
                if(c.compare(arr[j],arr[j+1])>0){
                    int tem=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=tem;
                }
            }
        }
    }
    //打印数组
    public void print(int[]arr){
        for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }
    }
}

interface Compare{
    public int compare(int num1,int num2);
}
